#!/usr/bin/python
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey,Enum
from sqlalchemy.orm import mapper
from sqlalchemy.orm import sessionmaker
import db_init
import pprint

class movie_queue(object):

	def __init__(self):
		self.video_url 			= "";
		self.video_product		= "";
		self.video_istranslate     	= "";
		self.video_downloadname    	= "";
		self.video_from            	= "";
		self.video_title           	= "";
		self.video_describe        	= "";
		self.video_status       	= "";
		self.video_format		= "";
		self.video_product_id		= -1




	def parser_youtube_set(self,product,url,title,des,product_id):
		self.video_product		= product;
		self.video_url			= url;
		self.video_istranslate		= 'n';
		self.video_from			= 'youtube';
		self.video_title		= title;
		self.video_describe		= des;
		self.video_status		= 'wait_verify';
		self.video_product_id		= product_id
		return;
	def download_yoube_set(self,status,format):
		self.video_status = status;
		self.video_format = format;
	

#map the object to table
mapper(movie_queue,db_init.movie_queue_table);
if __name__ == '__main__':
	#create session
	Session 		= sessionmaker(bind=db_init.engine)
	session			= Session();

	add_movie = movie_queue();
	add_movie.parser_youtube_set('test method.1','zzzz','title','some descrivbe');
	session.add(add_movie);
	print len(session.new._members ),len(session.dirty._members)
	print "before commit"
	for row in  session.query(movie_queue).filter_by(video_status='wait_download'):
		print row.id ,row.video_url,row.video_status,row.video_product
	session.commit();
	print "affter commit";
	for row in  session.query(movie_queue).filter_by(video_status='wait_download'):
		print row.id ,row.video_url,row.video_status,row.video_product


	print len(session.new._members ),len(session.dirty._members)
	print "before commit"
	for row in  session.query(movie_queue).filter_by(video_status='wait_download'):
		print row.id ,row.video_url,row.video_status,row.video_product
	print len(session.new._members )
	add_movie.parser_youtube_set('test method.3','aazzaa','zzzz','title','some descrivbe');

	print id(add_movie)
	print len(session.new._members ),len(session.dirty._members)

	session.add(add_movie);
	session.commit();
	print "after commit"
	print len(session.new._members ),len(session.dirty._members)



	for row in  session.query(movie_queue).filter_by(video_status='wait_download'):
		print row.id ,row.video_url,row.video_status,row.video_product
